import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            name: 'Index',
            component: () => import('@/views/index.vue'),
        },
        {
            path: '/auth/login',
            name: 'authLogin',
            component: () => import('@/views/auth/login.vue'),
        },
        {
            path: '/user/index',
            name: 'userIndex',
            component: () => import('@/views/user/index.vue'),
        },
        {
            path: '/cloud-disk/index',
            name: 'cloudDiskIndex',
            component: () => import('@/views/cloudDisk/index.vue'),
        },
        {
            path: '/doc/index',
            name: 'docIndex',
            component: () => import('@/views/doc/index.vue'),
        },
        {
            path: '/more/index',
            name: 'moreIndex',
            component: () => import('@/views/more/index.vue'),
        }
    ],
})

router.beforeEach(async (to, from) => {
    if (to.path !== '/auth/login' && !window.isLogin) {
        return router.replace({name: 'authLogin'})
    }
})

export default router
